import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;

/*Class used to store information about nodes in the system*/

public class MachineData {

	//fields used by all
	public String name;
	public int port;
	public InetAddress ip; 
	
	public MachineData(String ln) {
		String[] p = ln.split("\\s");
		String n = p[0];
		
		try {
			ip = InetAddress.getByName(n);
		}
		catch(UnknownHostException e) {
			System.out.println("Error: Couldn't find address.");
		}
		
		port = Integer.parseInt(p[1]);
		name = ip.getHostAddress();
	}
	
	public static ArrayList<MachineData> getList(String filename) {
		ArrayList<String> data = (new FileRead(filename)).getLines();
		ArrayList<MachineData> mData = new ArrayList<MachineData>();
		
		for(String s: data) {
			mData.add(new MachineData(s));
		}
		
		return mData;
	}
}
